<template>
<div class="app-container">
  <loading v-show="loading"></loading>
  <el-card class="box-card searchFormStyle" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>考核指标操作</span>
    </div>
    <div class="text item">
      <el-form ref="searchData" :model="searchData" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item  label="指标类型">
                <el-select v-model="searchData.ndexTypeKey" placeholder="请选择指标类型" class="tree-select">
                  <el-option
                    v-for="item in dzbIndexTypeList"
                    :key="item.ndexTypeKey"
                    :label="item.typeName"
                    :value="item.ndexTypeKey">
                  </el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item  label="党组织机构类别">
                <el-select v-model="searchData.partyOrgType" placeholder="请选择党组织机构类别"  class="tree-select">
                  <el-option
                    v-for="item in partyOrgTypeList"
                    :key="item.paramValue"
                    :label="item.paramName"
                    :value="item.paramValue">
                  </el-option>
                </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item>
              <el-button type="primary" 
              icon="el-icon-search" 
              v-if="permissionHandle('partyBranchExam:getList')"
              @click="getList">查 询</el-button>
              <el-button type="primary" 
              icon="el-icon-refresh" 
              v-if="permissionHandle('partyBranchExam:getList')"
              @click="resetSearch">重 置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
  <el-card class="box-card" style="margin-bottom:1%;">
    <div slot="header" class="clearfix">
      <span>考核指标列表</span>
    </div>
    <el-table
      :data="tableData"
      border
      ref="tableData"
      style="width: 100%;margin-bottom:1%;"
      >
      <!-- <el-table-column
        label="考核周期名称"
        width="180">
        <template slot-scope="scope">
            {{ scope.row.cycleAssessmenKey }}
        </template>
      </el-table-column> -->
      <el-table-column
        label="指标类型名称"
        width="180"
      >
        <template slot-scope="scope">
            {{ scope.row.ndexTypeKey }}
        </template>
      </el-table-column>
      <el-table-column
        label="党支部机构类型"
        width="180"
      >
        <template slot-scope="scope">
            {{ scope.row.partyOrgType }}
        </template>
      </el-table-column>
      <el-table-column
        label="考核指标名称"
      >
        <template slot-scope="scope">
            {{ scope.row.jgIndexName }}
        </template>
      </el-table-column>
      <el-table-column
        label="考核指标权重"
        width="150"
      >
        <template slot-scope="scope">
            {{ scope.row.weights }}
        </template>
      </el-table-column>
      <el-table-column
        label="排序"
        width="100"
      >
        <template slot-scope="scope">
            {{ scope.row.sortNumber }}
        </template>
      </el-table-column>
      <el-table-column
        label="创建日期"
        width="180px"
      >
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            icon="el-icon-document"
            v-if="permissionHandle('partyBranchExam:handleDetails')"
            @click="handleDetail(scope.$index, scope.row)">详细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" :paginations="paginations"></pagination>
  </el-card>
  <!--新增参数类型-->
 <el-dialog :title="dialogTitle" :visible.sync="detailFormVisible" width="80%">
    <el-form :model="detailData"  disabled ref="detailData" label-width="140px" class="detailStyle" style="margin-bottom:40px;">
      <el-row>
          <el-col :span="8">
            <span class="labelSpan">
              考核周期名称:
            </span>
            <span class="valueSpan">
              {{detailData.cycleAssessmenKey}}
            </span>
          </el-col>
          <el-col :span="8">
            <span class="labelSpan">
              指标名称:
            </span>
            <span class="valueSpan">
              {{detailData.jgIndexName}}
            </span>
          </el-col>
          <el-col :span="8">
            <span class="labelSpan">
              指标类型:
            </span>
            <span class="valueSpan">
              {{detailData.ndexTypeKey}}
            </span>
          </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
            <el-form-item label="党组织机构类别:">
              <el-select v-model="detailData.partyOrgType"  placeholder="请选择" style="width:100%;">
                <el-option
                  v-for="item in partyOrgTypeList"
                  :key="item.paramValue"
                  :label="item.paramName"
                  :value="item.paramValue">
                </el-option>
              </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <span class="labelSpan">
              指标权重:
            </span>
            <span class="valueSpan">
              {{detailData.weights}}
            </span>
        </el-col>
        <el-col :span="8">
            <span class="labelSpan">
              排序:
            </span>
            <span class="valueSpan">
              {{detailData.sortNumber}}
            </span>
        </el-col>
      </el-row>
    </el-form>
 </el-dialog>
</div>
</template>
<script>
import Loading from '@/components/loading/loading'
import pagination from '@/components/pagination/index'
import { getMember, getMemberDetail } from '@/api/partyBranch/partyBranchExam'
export default {
  components: {
    Loading,
    pagination
  },
  data() {
    this.permissionHandle = this.$permissionHandle
    return {
      paginations: {
        totalNum: 0,
        currentPage: 1,
        pageSize: 10
      },
      searchData: {
        ndexTypeKey: '',
        partyOrgType: '',
        pageSize: '10',
        pageNum: '1'
      },
      detailData: {
        createTime: '',
        cycleAssessmenKey: '',
        indexHistoryKey: '',
        jgIndexName: '',
        ndexTypeKey: '',
        partyOrgType: '',
        sortNumber: '',
        weights: ''
      },
      dzbIndexTypeList: [],
      partyOrgTypeList: [],
      loading: false,
      tableData: [],
      dialogTitle: '考核指标详细',
      // 新增角色数据
      addForm: {
        indexHistoryKey: ''
      },
      dialogFormVisible: false, // 新增弹出框状态
      Exam: [],
      ExamType: [],
      detailFormVisible: false
    }
  },
  created() {
    this.getExamList()
  },
  methods: {
    resetSearch() {
      this.searchData.ndexTypeKey = ''
      this.searchData.partyOrgType = ''
      this.getExamList()
    },
    getList() {
      this.searchData.pageNum = 1
      this.getExamList()
      this.paginations.currentPage = 1
    },
    // 查询参数
    getExamList() {
      this.loading = true
      return new Promise((resolve, reject) => {
        getMember(this.searchData).then(response => {
          this.tableData = response.data.entity.items
          this.dzbIndexTypeList = response.data.dzbIndexType
          this.partyOrgTypeList = response.data.partyOrgType
          this.paginations.totalNum = parseInt(response.data.entity.itemsTotalCount)
          this.loading = false
          resolve()
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    handleDetail(index, row) {
      this.detailFormVisible = true
      this.addForm.indexHistoryKey = row.indexHistoryKey
      return new Promise((resolve, reject) => {
        getMemberDetail(this.addForm).then(response => {
          this.partyOrgTypeList = response.data.PARTYORGTYPE
          this.detailData = response.data.entity
          this.loading = false
          resolve()
        }).catch(error => {
          this.loading = false
          reject(error)
        })
      })
    },
    // 输入参数查询之后
    blurSearch(value) {
      this.getList()
    },
    handleSizeChange(val) {
      this.searchData.pageSize = val
      this.getExamList()
    },
    handleCurrentChange(val) {
      this.searchData.pageNum = val
      this.getExamList()
    }
  }
}
</script>
<style lang="scss">
  .tree-input{
    position: relative;
  }
  .input-tree{
      height:200px;width: 100%;
      .el-scrollbar__wrap{overflow: auto;}
    }
    .detail-col{height:40px;line-height: 40px;}
  .title-span{font-size: 16px;display:inline-block;width:100%;height:40px;line-height:40px;border-bottom:1px solid #e6e6e6}

</style>
